<?php

namespace App\Http\Controllers\Admin\Ad;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Http\Controllers\Admin\CommonController;
use App\Models\wechat\ad_category;

class CategoryController extends CommonController
{
    public function __construct()
    {
        parent::__construct();
        view()->share([
            '_system'=>'ads',
            '_ad'=>'am-active',

        ]);
    }
    //显示广告分类
   public function index()
   {
       $categories=ad_category::get();
       return view('admin.ads.category.index')->with('categories',$categories)->with(['_adCategory'=>'am-active','_ad'=>'']);
   }

    //显示新增广告分类
    public function create()
    {
        return view('admin.ads.category.create');
    }
    //执行广告分类存储
    public function store(Request $request)
    {
        ad_category::create($request->all());
        return redirect(route('ads.category.index'));
    }
    //编辑广告分类
    public function edit($id)
    {
        $category=ad_category::find($id);
        return view('admin.ads.category.edit')->with('category',$category);
    }
    //更新
    public function update(Request $request,$id)
    {
//        return $request->all();
        $category=ad_category::find($id);
        $category->update($request->all());
        return redirect(route('ads.category.index'));
    }
    //删除
    public function destroy($id)
    {
        ad_category::destroy($id);
        return redirect(route('ads.category.index'));

    }



    //排序
    public function sort_order(Request $request)
    {
        $category=ad_category::find($request->id);
        $category->sort_order=$request->sort_order;
        $category->save();
    }
}
